function omega = cal_omega(cand,lcv_cal,t_rd,pars,sao60_uniform)

a=cand(:,1); b=cand(:,2); c=cand(:,3);
i=cand(:,4); j=cand(:,5); k=cand(:,6);

% --------------- calculate omega ----------------- %
d12_t = sao60_uniform(a,2:4)*sao60_uniform(b,2:4)';
d23_t = sao60_uniform(b,2:4)*sao60_uniform(c,2:4)';
d13_t = sao60_uniform(a,2:4)*sao60_uniform(c,2:4)';

d12=cal_dist_cos(lcv_cal(i,4:5), lcv_cal(j,4:5), pars);
d23=cal_dist_cos(lcv_cal(j,4:5), lcv_cal(k,4:5), pars);
d13=cal_dist_cos(lcv_cal(i,4:5), lcv_cal(k,4:5), pars);

% t12 = round((lcv_cal(i,5)-lcv_cal(j,5)))*t_rd;
% t23 = round((lcv_cal(j,5)-lcv_cal(k,5)))*t_rd;
% t13 = round((lcv_cal(i,5)-lcv_cal(k,5)))*wt_rd;

t12 = (lcv_cal(i,5)-lcv_cal(j,5))*t_rd;
t23 = (lcv_cal(j,5)-lcv_cal(k,5))*t_rd;
t13 = (lcv_cal(i,5)-lcv_cal(k,5))*t_rd;

% --------- a1 --------- %
a12 = (lcv_cal(i,3)*lcv_cal(j,2)-lcv_cal(i,2)*lcv_cal(j,3))*t12;
b12 = (lcv_cal(i,1)*lcv_cal(j,3)-lcv_cal(i,3)*lcv_cal(j,1))*t12;
c12 = (lcv_cal(i,2)*lcv_cal(j,1)-lcv_cal(i,1)*lcv_cal(j,2))*t12;
% --------- a2 --------- %
a23 = (lcv_cal(j,3)*lcv_cal(k,2)-lcv_cal(j,2)*lcv_cal(k,3))*t23;
b23 = (lcv_cal(j,1)*lcv_cal(k,3)-lcv_cal(j,3)*lcv_cal(k,1))*t23;
c23 = (lcv_cal(j,2)*lcv_cal(k,1)-lcv_cal(j,1)*lcv_cal(k,2))*t23;
% --------- a3 --------- %
a13 = (lcv_cal(i,3)*lcv_cal(k,2)-lcv_cal(i,2)*lcv_cal(k,3))*t13;
b13 = (lcv_cal(i,1)*lcv_cal(k,3)-lcv_cal(i,3)*lcv_cal(k,1))*t13;
c13 = (lcv_cal(i,2)*lcv_cal(k,1)-lcv_cal(i,1)*lcv_cal(k,2))*t13;
% --------- a4 --------- %
A = [a12 b12 c12;a23 b23 c23;a13 b13 c13];
B = [d12-d12_t; d23-d23_t; d13-d13_t];

if rank(A) ~= 3
    omega = [];
else
    omega = (A'*A)\(A'*B);
end
end